

//获取到三级联动的地址


$('#address').on('tap', function () {
  var picker = new mui.PopPicker({
    layer:3
  });
  picker.setData(cityData);
  picker.show(function (selectItems) {
    console.log(selectItems);
    var province=selectItems[0].text
    var city=selectItems[1].text
    var area=selectItems[2].text
   var allAddress=province+city+area
   $("#address").val(allAddress)




  })

})





// 添加收货地址业务逻辑
$("#addBtnAddress").on("tap", function (e) {
  var user = $("#user").val().trim();
  var post_code = $("#post_code").val().trim();

  var address = $("#address").val().trim();
  var detail_address = $("#detail_address").val().trim();

  if (user.length < 5) return alert("用户名最短为 5 个字符");


  if (post_code.length < 6) return alert("邮编最短为 6 个字符");

  if (address && address.length < 2) return alert("地址必须写而且最短为 2 个字符");
  if (detail_address && detail_address.length < 2) return alert("详细地址必须写最短为 2 个字符");









  // address  三级联动地址
  // addressDetail  详细地址
  // recipients 收货人
  // postcode 邮编

  var params = {
    recipients: user,
    postcode: post_code,
    address: address,
    addressDetail: detail_address


  };

  $.ajax({
    url: "/address/addAddress",
    type: "post",
    data: params,
    success: function (res) {
      console.log(res);
      if (res.success) {
        setTimeout(function () {
          window.location.href = "address.html";
        }, 1000);
      }
    },
  });
});

